#ifndef CAMERAHANDLER_H
#define CAMERAHANDLER_H

#include <QObject>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QVideoProbe>
#include <QVideoFrame>
#include <QImage>
#include <QAbstractVideoSurface>
#include <QByteArray>
#include <QTimer>

class VideoSurface: public QAbstractVideoSurface
{
    Q_OBJECT
public:
    VideoSurface(QObject *parent = nullptr);
    virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType = QAbstractVideoBuffer::NoHandle) const override;
    bool present(const QVideoFrame &frame) override;
signals:
    void videoChanged(QVideoFrame);
};

class CameraHandler : public QObject
{
    Q_OBJECT
public:
    explicit CameraHandler(QObject *parent = nullptr);
    void setImageQuality(int value);

private:
    QCamera *camera;
    int imageQuality = 0;
    int fps = 0;
    QTimer *timer;
public slots:
    void onBtnChange();

private slots:
    void onVideoChanged(QVideoFrame curframe);
    void onTimerout();
signals:
    void videoUpdate(QImage& map);
    void sendVideo(QByteArray byte);
    void cameraChanged(QCamera::State state);
    void getFps(int value);
};

#endif // CAMERAHANDLER_H
